<?php

session_start();
include_once '../pushing.php';

if ($pushTime == true) {
	if ($_SESSION['UserId'] != 3)
		header('Location: push.php');
}

if(!isset($_SESSION['UserId']))
{
	header('Location: login.php');
	die();
}

require_once '../mysqlConnect.php';
require_once '../Model/Medication.php';

$ValidationErrors = null;

if (isset($_POST['medication_name'])) {
	
	$medication = new Medication();
	$medication->set(array('Name' => $_POST['medication_name']));

	$save = $medication->save();
	if ($save === true) {
		echo '<script language="javascript" type="text/javascript">
		
			function redirect(){
				window.location.href = "home.php";
			}
			
			alert("Successfully Added Medication to Database!");
			redirect();
		
		</script>';
	} else
		$ValidationErrors = $save;
}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Add Medication</title>
		<link rel="stylesheet" type="text/css" href="../Styler.css" />

	</head>

	<body>
	
	<div id="header"><div class="pageTitleText">Add To Database</div></div>
   	 
    <div id="mainMenu" style="height: 65px; width: 100px;">
    	<ul style="list-style: none outside none;">
	        <li>
	       	 	<a href="home.php">Cancel</a>
	        </li> 
	         
	        <li>
	       	 	<a href="logout.php">Logout</a>
	        </li>
	        
        </ul>
	</div>
     
     <?php if(isset($ValidationErrors)) {?>
			
			<div class="noQueryResults">
			    <img src="../Images/error.png" style="float:left; margin: 5px 5px 5px 15px;"></img>
			    <p style="font-weight: bold; line-height: 1; margin: 5px 5px 5px 55px;">Error</p>
				<p style="line-height: 1; margin: 5px 5px 5px 55px;">		
		    	<?php echo $ValidationErrors;?>
		    	</p>
			</div>
			
    <?php } ?>
     
     
     
	<div class="formContainer">
		<div id="login" style="top: 10px; margin: 0px; width: 600px; height: 200px;"> 
		
	        <form name="addMedicationForm" method="post">
	             
				<div style="border-bottom: 1px solid #CCC; padding-bottom: 10px;">    
	                <label for="medication_name" style="padding-right: 20px;">Medication Name</label>
	                <input type="text" id="medication_id" name="medication_name" style="width: 450px;"></input>
				</div>
	         	
            	<div id="QuesButton">
            	 	<input type="submit" value="Submit" class="loginButton" style="margin-top: 0px;"/>
		        </div>    	
	        	
	        </form>
	        
		</div>
	</div>

     
	</body>
</html>
